package com.feri.rbacsys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.feri.rbacsys.bo.GiftBo;
import com.feri.rbacsys.dao.ProductDao;
import com.feri.rbacsys.entity.Product;
import com.feri.rbacsys.service.intf.ProductService;
import com.feri.rbacsys.vo.R;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;

/**
 * (Product)表服务实现类
 *
 * @author makejava
 * @since 2023-03-27 21:00:21
 */
@Service
public class ProductServiceImpl extends ServiceImpl<ProductDao, Product> implements ProductService {

    @Resource
    private ProductDao dao;

    @Override
    public R queryAll() {
        return new R(0,"OK",dao.selectAll());
    }

    @Override
    public R queryWhere(Product product) {
        //1.实例化 条件构造器对象
        QueryWrapper<Product> queryWrapper=new QueryWrapper<>();
        //2.动态设置条件
        if(product.getId()!=null){
            queryWrapper.like("id",product.getId());
        }
        if(StringUtils.hasLength(product.getName())){
            queryWrapper.like("name",product.getName());
        }
        //排序
        queryWrapper.orderByDesc("id");
        //3.执行查询
        return new R(0,"OK",dao.selectList(queryWrapper));
    }
}

